package com.xsm.ppsecret.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.jaeger.library.StatusBarUtil;
import com.xsm.ppsecret.R;
import com.xsm.ppsecret.presenter.LoginPresenter;
import com.xsm.ppsecret.ui.implview.ILoginActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class LoginActivity extends BaseActivity implements ILoginActivity {

    private static final String TAG = "LoginActivity";
    @BindView(R.id.main_edit)
    EditText pwdEdit;
    @BindView(R.id.main_img)
    ImageView unlocking;
    private LoginPresenter mPresenter = new LoginPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, getResources().getColor(R.color.appColor), 0);
    }

    @Override
    protected void onStart() {
        super.onStart();
        pwdEdit.setText("");
    }

    @OnClick(R.id.tv_forget) void forgetPassword() {
        startActivity(new Intent(this, ForgetPasswordActivity.class));
    }

    @OnClick(R.id.main_img) void unLockClick() {
        mPresenter.unLock(pwdEdit.getText().toString());
    }

    @Override
    public void unLockOk() {
        startActivity(new Intent(this, ShowActivity.class));
    }

    @Override
    public void unLockError(String errorMsg) {
        Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
        pwdEdit.setText("");
        pwdEdit.setHint(errorMsg);
        pwdEdit.setHintTextColor(getResources().getColor(R.color.red_remind));
    }
}
